package org.qfedu.edu.auto;

import org.qfedu.edu.service.INetworkService;
import org.qfedu.edu.service.NetworkService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.boot.autoconfigure.EnableAutoConfiguration;
import org.springframework.boot.autoconfigure.condition.ConditionalOnBean;
import org.springframework.boot.autoconfigure.condition.ConditionalOnClass;
import org.springframework.boot.autoconfigure.condition.ConditionalOnMissingBean;
import org.springframework.boot.context.properties.EnableConfigurationProperties;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;

/**
 *
 */
@Configuration
@ConditionalOnClass(NetworkService.class)//在类的路径下必须拥有这个类才使能
@EnableConfigurationProperties(NetworkServiceProperties.class)//使能这个配置文件
public class NetworkServiceAutoConfiguration {

    @Bean
    @ConditionalOnMissingBean//当容器中没有这个bean才创建这个bean
    public INetworkService networkService(@Autowired NetworkServiceProperties networkServiceProperties){
        NetworkService networkService = new NetworkService();
        networkService.setHost(networkServiceProperties.getHost());
        networkService.setPort(networkServiceProperties.getPort());
        return networkService;
    }
}
